
import  React, { Component } from 'react';
import {InputNumber } from 'antd';
class  Good   extends   Component{
    static defaultProps={

          money:0,
          id:0,
          mount:0,
        name:'未知',


    }

    constructor(props) {
        super();

        this.state = {
              money:  props.money  ||  Good.defaultProps.money   ,
             id: props.id ||  Good.defaultProps.id,
            mount:  props.mount  ||   Good.defaultProps.mount,
            total:0,
            lasttotal:0
        }
     //   this.gettotalmoney.bind(this)

             this.gettotalmoney=this.gettotalmoney.bind(this);
             this.sendfatherstate=this.sendfatherstate.bind(this);



    }

    gettotalmoney() {

        this.setState({
            total:this.state.money*this.state.mount

        },()=> {    this.sendfatherstate()})



    }

    sendfatherstate(){
      let  difference=this.state.total-this.state.lasttotal;
        this.props.son( difference);
        console.log('发送总额'+difference)
        this.state.lasttotal=this.state.total;

    }

    setmount(value) {

        this.setState({

            mount:value

        },() => this.gettotalmoney());


        console.log(value);

    }

    componentDidMount(){



          this.gettotalmoney()




    }
    componentWillUpdate(){




    }
    render() {



        return(
            <div>
               单价 { this.state.money   }   数量  {   this.state.mount   }   总价 {   this.state.total }
                <InputNumber min={1} max={10} defaultValue={0} onChange={this.setmount.bind(this)} />

            </div>

        );


    }



}

export default  Good;